<template>
	<view>
		<view class="tianQi">
			<view class="chengShi">
				<image src="../../static/定向.png" mode=""></image>{{address}}
			</view>
			<view class="qi">
				<p>当前天气:{{addressArr==null?"":addressArr.weatherConditions}}</p>
			</view>
			<view>
				<view class="maxWenDu">今日气温:{{addressArr==null?"":addressArr.intervalTemperature}}℃</view>
			</view>
		</view>
		<view class="wenshidu">
			<view class="shiDu">
				<view>湿度：{{addressArr==null?"":addressArr.humidity}}%</view>
			</view>
			<view class="">
				<image src="../../static/大雨.png" mode="widthFix"
					v-if="addressArr==null?false:addressArr.weatherConditions=='雨'"></image>
				<image src="../../static/大雪.png" mode="widthFix"
					v-else-if="addressArr==null?false:addressArr.weatherConditions=='雪'"></image>
				<image src="../../static/烈日.png" mode="widthFix"
					v-else-if="addressArr==null?false:addressArr.weatherConditions=='晴'"></image>
				<image src="../../static/浓云.png" mode="widthFix"
					v-else-if="addressArr==null?false:addressArr.weatherConditions=='多云'"></image>
			</view>
			<view class="fengSu">
				<view>风速：{{addressArr==null?"":addressArr.descriptionOfTheCurrentWindDirection}}km/h</view>
			</view>
		</view>
		<!-- <uni-combox label="所在城市" :candidates="CityList" placeholder="请选择所在城市" v-model="city"
			@click="combox()"></uni-combox> -->
	</view>
</template>

<script setup>
	uni.setStorageSync("ulr", "http://124.93.196.45:10001")
	var ulr = uni.getStorageSync("ulr")
	export default {
		data() {
			return {
				city: "",
				CityList: [],
				address: "",
				addressArr: null,
				token: "",
				data: null,
				Specifydata: null
			}
		},
		onLoad() {
			if (uni.getStorageSync("token") == "") {
				uni.showToast({
					title: "暂未登录,跳转到主页",
					icon: 'none',
					duration: 2000
				})
			}
			var today = new Date();
			
			var date = today.getDate();
			uni.request({
				method: 'POST',
				url: ulr + "/dev-api/login",
				data: {
					"username": "16613322619",
					"password": "123456"
				},
				complete: (res) => {
					this.token = res.data.token;
					uni.request({
						method: 'GET',
						url: ulr + "/dev-api/common/city/page",
						header: {
							"Authorization": "Bearer " + this.token
						},
						complete: (res) => {
							this.data = res.data.rows
							this.address = "大连市"
							this.Specify_data()
							this.shuju()
						}

					})
				}

			})



		},
		methods: {
			async Specify_data() {
				const response = await uni.request({
					method: 'GET',
					url: ulr + "/dev-api/bs-weather-report/weather/queryLastSevenDaysData/" + this.address,
					header: {
						"Authorization": "Bearer " + this.token
					}
				})
				this.addressArr = response.data.data[0]
			},
			shuju() {
				for (var i = 0; i < this.data.length; i++) {
					this.CityList.push(this.data[i].name)
				}

			},
			combox() {
				this.token = this.city
				this.Specify_data()
			}
		}
	}
</script>

<style lang="scss" scoped>
	.tianQi {
		margin: 0 0 20rpx 0;
		display: flex;
		justify-content: space-evenly;
		font-size: 100rpx;
	}

	.maxWenDu {}

	.wenshidu {
		display: flex;
		align-items: center;
		justify-content: space-evenly;
	}

	.wenshidu image {
		width: 150px;
	}

	.qi {
		display: flex;
		flex-direction: column;
		justify-content: center;
		text-align: center;
	}

	.chengShi>image {
		width: 50px;
		height: 50px;
	}

	.tianQi>view {
		line-height: 200rpx;
	}

	.tianQi>view>view {
		font-size: 50rpx;
	}

	.shiDu {
		padding: 0 10%;
		margin: 20rpx 0;
		font-size: 50rpx;
	}

	.fengSu {
		padding: 0 10%;
		margin: 20rpx 0;
		display: flex;
		justify-content: space-between;
		font-size: 50rpx;
	}
</style>